import {BSFormatParserV2} from "./MapParser/BSFormatParserV2"
import {BSFormatParserV4} from "./MapParser/BSFormatParserV4"

function constructMapParser(item, data) {
  let version = "2.0.0";

  if ("version" in data) {
    version = data["version"];
  } else if ("_version" in data) {
    version = data["_version"];
  } else {
    console.error("No version in data");
    return null;
  }

  switch (version) {
    case "2.0.0":
    case "2.1.0":
      return new BSFormatParserV2(item, data);
    case "4.0.0":
    case "4.0.1":
      return new BSFormatParserV4(item, data);
    default:
      console.error("Unknown version: " + version);
      return null;
  }
}

module.exports = { constructMapParser };